home *** CD-ROM | disk | FTP | other *** search
/ CICA 1995 September (Japanese) / CICA Shareware for Windows CD-ROM (Walnut Creek) (September 1995) (Japanese) (Disc 2).iso / disc2 / nt / ntperf.exe / PERFTOOLS / SRC / PERFMON / EXPORT.C_ / EXPORT.C
Encoding:
C/C++ Source or Header  |  1993-05-15  |  7.1 KB  |  250 lines

  1. #include "perfmon.h"
  2. #include <lmcons.h>
  3. #include <lmerr.h>
  4. #include <lmapibuf.h>
  5. #include <lmwksta.h>
  6. // #include <uiexport.h>
  7. #include <stdio.h>         // for sprintf
  8. #include "utils.h"
  9.  
  10. #include "perfmops.h"      // for SystemTimeDateString
  11. #include "fileopen.h"      // for FileGetName
  12. #include "fileutil.h"      // for FileRead etc
  13. #include "playback.h"      // for PlayingBackLog & LogPositionSystemTime
  14. #include "dlgs.h"          // common dialog control IDs
  15. #include "pmhelpid.h"      // Help IDs
  16.  
  17.  
  18. // This routine opens the export file and put in the header info.
  19. // It is used by ExportChart, ExportAlert, & ExportReport.
  20. INT  ExportFileOpen (HWND hWnd, HANDLE *phFile, int IntervalMSecs, LPTSTR *ppFileName)
  21. {
  22.    CHAR           TempBuff [LongTextLen] ;
  23.    TCHAR          UnicodeBuff [LongTextLen] ;
  24.    TCHAR          UnicodeBuff1 [MiscTextLen] ;
  25.    SYSTEMTIME     SystemTime ;
  26.    int            StringLen ;
  27.    INT            ErrCode = 0 ;
  28.    FLOAT          eIntervalSecs ;
  29.  
  30.    // defined and setup in status.c
  31.    extern TCHAR   szCurrentActivity [] ;
  32.    extern TCHAR   szStatusFormat [] ;
  33.  
  34.    *phFile = 0 ;
  35.  
  36.    if (!FileGetName (hWnd, IDS_EXPORTFILE, UnicodeBuff))
  37.       {
  38.       // user cancel 
  39.       goto Exit0 ;
  40.       }
  41.  
  42.    *ppFileName = StringAllocate (UnicodeBuff) ;
  43.  
  44.    // open the file..
  45.    if (!(*phFile = FileHandleCreate (UnicodeBuff)))
  46.       {
  47.       // can't open the file
  48.       ErrCode = ERR_CANT_OPEN ;
  49.       goto Exit0 ;
  50.       }
  51.  
  52.  
  53.    // export header
  54.    StringLoad (IDS_REPORT_HEADER, UnicodeBuff) ;
  55.    ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  56.    StringLen = strlen (TempBuff) ;
  57.    ConvertUnicodeStr (&TempBuff[StringLen], LocalComputerName) ;
  58.    strcat (TempBuff, LineEndStr) ;
  59.  
  60.    if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  61.       {
  62.       ErrCode = ERR_EXPORT_FILE ;
  63.       goto Exit0 ;
  64.       }
  65.  
  66.    // export today's date time
  67.    GetLocalTime (&SystemTime) ;
  68.  
  69.    StringLoad (IDS_EXPORT_DATE, UnicodeBuff) ;
  70.    StringLen = lstrlen (UnicodeBuff) ;
  71.    UnicodeBuff[StringLen] = TEXT(':') ;
  72.    UnicodeBuff[StringLen+1] = TEXT(' ') ;
  73.    SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen+2]) ;
  74.    ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  75.    strcat (TempBuff, LineEndStr) ;
  76.  
  77.    if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  78.       {
  79.       ErrCode = ERR_EXPORT_FILE ;
  80.       goto Exit0 ;
  81.       }
  82.  
  83.    StringLoad (IDS_EXPORT_TIME, UnicodeBuff) ;
  84.    StringLen = lstrlen (UnicodeBuff) ;
  85.    UnicodeBuff[StringLen] = TEXT(':') ;
  86.    UnicodeBuff[StringLen+1] = TEXT(' ') ;
  87.    SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen+2]) ;
  88.    ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  89.    strcat (TempBuff, LineEndStr) ;
  90.  
  91.    if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  92.       {
  93.       ErrCode = ERR_EXPORT_FILE ;
  94.       goto Exit0 ;
  95.       }
  96.  
  97.  
  98.    // export data source
  99.    TSPRINTF (UnicodeBuff, szStatusFormat,
  100.       PlayingBackLog () ?
  101.       PlaybackLog.szFileTitle : szCurrentActivity) ;
  102.    ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  103.    strcat (TempBuff, LineEndStr) ;
  104.    
  105.    if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  106.       {
  107.       ErrCode = ERR_EXPORT_FILE ;
  108.       goto Exit0 ;
  109.       }
  110.  
  111.  
  112.    if (!PlayingBackLog())
  113.       {
  114.          
  115.       eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ;
  116.       StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ;
  117.       TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ;
  118.  
  119.       ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  120.       strcat (TempBuff, LineEndStr) ;
  121.    
  122.       if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  123.          {
  124.  
  125.          ErrCode = ERR_EXPORT_FILE ;
  126.          goto Exit0 ;
  127.          }
  128.       }
  129.    else
  130.       {
  131.       // export the log start and stop date/time
  132.       StringLoad (IDS_START_TEXT, UnicodeBuff) ;
  133.       StringLen = lstrlen (UnicodeBuff) ;
  134.       LogPositionSystemTime (&(PlaybackLog.StartIndexPos), &SystemTime) ;
  135.       SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ;
  136.       StringLen = lstrlen (UnicodeBuff) ;
  137.       UnicodeBuff[StringLen] = TEXT(' ') ;
  138.       StringLen++ ;
  139.       SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen]) ;
  140.       ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  141.       strcat (TempBuff, LineEndStr) ;
  142.  
  143.       if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  144.          {
  145.  
  146.          ErrCode = ERR_EXPORT_FILE ;
  147.          goto Exit0 ;
  148.          }
  149.  
  150.       StringLoad (IDS_STOP_TEXT, UnicodeBuff) ;
  151.       StringLen = lstrlen (UnicodeBuff) ;
  152.       LogPositionSystemTime (&(PlaybackLog.StopIndexPos), &SystemTime) ;
  153.       SystemTimeDateString (&SystemTime, &UnicodeBuff[StringLen]) ;
  154.       StringLen = lstrlen (UnicodeBuff) ;
  155.       UnicodeBuff[StringLen] = TEXT(' ') ;
  156.       StringLen++ ;
  157.       SystemTimeTimeString (&SystemTime, &UnicodeBuff[StringLen]) ;
  158.       ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  159.       strcat (TempBuff, LineEndStr) ;
  160.  
  161.       if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  162.          {
  163.          ErrCode = ERR_EXPORT_FILE ;
  164.          goto Exit0 ;
  165.          }
  166.  
  167.       if (hWnd == hWndAlert)
  168.          {
  169.          eIntervalSecs = (FLOAT)IntervalMSecs / (FLOAT) 1000.0 ;
  170.          StringLoad (IDS_CHARTINT_FORMAT, UnicodeBuff1) ;
  171.          TSPRINTF (UnicodeBuff, UnicodeBuff1, eIntervalSecs) ;
  172.  
  173.          ConvertUnicodeStr (TempBuff, UnicodeBuff) ;
  174.          strcat (TempBuff, LineEndStr) ;
  175.       
  176.          if (!FileWrite (*phFile, TempBuff, strlen(TempBuff)))
  177.             {
  178.             ErrCode = ERR_EXPORT_FILE ;
  179.             goto Exit0 ;
  180.             }
  181.          }
  182.       
  183.       }
  184.  
  185.    return (0) ;
  186.  
  187. Exit0:
  188.  
  189.    return (ErrCode) ;
  190.  
  191. }  // ExportFileOpen
  192.  
  193.  
  194.  
  195. BOOL APIENTRY ExportOptionsHookProc (HWND hDlg, 
  196.                                      UINT iMessage, 
  197.                                      WPARAM wParam, 
  198.                                      LPARAM lParam)
  199.  
  200. {
  201.    BOOL           bHandled ;
  202.  
  203.    bHandled = TRUE ;
  204.    switch (iMessage)
  205.       {
  206.       case WM_INITDIALOG:
  207.          CheckRadioButton (hDlg, IDD_EXPORTCOMMAS, IDD_EXPORTTAB,
  208.             pDelimiter == TabStr ? IDD_EXPORTTAB : IDD_EXPORTCOMMAS ) ;
  209.  
  210.          WindowCenter (hDlg) ;
  211.          break ;
  212.  
  213.       case WM_COMMAND:
  214.          switch (wParam)
  215.             {  // switch
  216.             case IDD_EXPORTCOMMAS:
  217.             case IDD_EXPORTTAB:
  218.                // toggle between the 2 radio buttons..
  219.                CheckRadioButton (hDlg, IDD_EXPORTCOMMAS, IDD_EXPORTTAB,
  220.                   IsDlgButtonChecked (hDlg, IDD_EXPORTCOMMAS) ?
  221.                      IDD_EXPORTTAB : IDD_EXPORTCOMMAS ) ;
  222.                break ;
  223.  
  224.             case IDD_OK:
  225.                pDelimiter = IsDlgButtonChecked (hDlg, IDD_EXPORTCOMMAS) ?
  226.                   CommasStr : TabStr ;
  227.                bHandled = FALSE ;
  228.  
  229.                break ;
  230.  
  231.             case IDD_EXPORTHELP:
  232.                CallWinHelp (dwCurrentDlgID) ;
  233.                break ;
  234.  
  235.             default:
  236.                bHandled = FALSE ;
  237.             }  // switch
  238.          break;
  239.  
  240.       default:
  241.          bHandled = FALSE ;
  242.          break;            
  243.       }  // switch
  244.  
  245.    return (bHandled) ;
  246.  
  247. }  // ExportOptionsHookProc
  248.  
  249. 
  250.